<template>
	<scroll-view class="page" scroll-y="true" @scrolltolower="loadDataFn">
		<xzfx-empty v-if="list.length === 0" tips="暂未求购" />
		<view class="want-bay-list">
			<view class="xzfx-want-bay-card" v-for="(item, index) in list" :key="index" @click.stop="$go('/pages/want-buy/details?my=0&id=' + item.id)">
				<view class="want-bay-info">
					<view class="label">期望品牌:</view>
					<view class="value">{{ item.truckBrand }}</view>
				</view>
				<view class="want-bay-info">
					<view class="label">期望马力:</view>
					<view class="value">{{ item.maxPower }}匹</view>
				</view>
				<view class="want-bay-info">
					<view class="label">期望年份:</view>
					<view class="value">{{ item.productYearStart }}年 - {{ item.productYearEnd }}年</view>
				</view>
				<view class="want-bay-info">
					<view class="label">期望地点:</view>
					<view class="value">{{ item.location }}</view>
				</view>
				<view class="want-bay-info">
					<view class="label">求购备注:</view>
					<view class="value">{{ item.remark }}</view>
				</view>
				<view class="want-bay-action">
					<view class="time"><text>发布时间:</text>{{ item.createTime }}</view>
					<view class="btn" @click.stop="$call(item.contackPhone)">立即联系</view>
				</view>
			</view>
		</view>
		<xzfx-divider v-if="list.length > 10">{{ dividerTitle }}</xzfx-divider>
		<view class="action">
			<view class="btn" @click.stop="$checkLogin(toMy)">我的求购</view>
			<view class="btn" @click.stop="$checkLogin(toPublish)">发布求购</view>
		</view>
	</scroll-view>
</template>

<script>
	export default {
		data() {
			return {
				total: 0,
				list: [],
				pageNo: 1,
				pageSize: 10,
				dividerTitle: "暂无更多"
			};
		},
		onShow() {
			this.refreshData()
		},
		methods: {
			toMy(){
				this.$go('/pages/my/my-want-buy');
			},
			toPublish(){
				this.$go('/pages/want-buy/publish');
			},
			refreshData(){
				this.pageNo = 1;
				this.pageSize = 10;
				this.total = 0;
				this.list = [];
				this.getDataFn()
			},
			loadDataFn(){
				if(this.total > this.list.length){
					this.pageNo = this.pageNo + 1
					this.getDataFn()
				}else{
					this.dividerTitle = "暂无更多"
				}
			},
			getDataFn(){
				this.dividerTitle = "加载中......"
				this.$apis.wantBuy.getList({
					type: 1,
					pageNo: this.pageNo,
					pageSize: this.pageSize
				}).then(res => {
					this.dividerTitle = "暂无更多"
					this.total = res.total
					this.list = this.list.concat(res.items)
				}).catch(err => {
					this.dividerTitle = "暂无更多"
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.page{
		height: 100vh;
	}
	.want-bay-list{
		padding-bottom: 120rpx;
		.xzfx-want-bay-card{
			margin: $xzfx-spacing;
			padding: $xzfx-spacing;
			border-radius: 20rpx;
			background-color: #fff;
			.want-bay-info{
				display: flex;
				padding: 10rpx 0;
				line-height: 36rpx;
				.label{
					width: 140rpx;
					color: #666666;
					font-size: 30rpx;
				}
				.value{
					width: calc(100% - 140rpx);
					color: #333333;
					font-size: 30rpx;
				}
			}
			.want-bay-action{
				display: flex;
				justify-content: space-between;
				align-items: center;
				border-top: 1rpx solid #f1f1f1;
				padding-top: 20rpx;
				margin-top: 10rpx;
				.time{
					font-size: 28rpx;
					color: #666666;
					text{
						font-size: 26rpx;
						padding-right: 10rpx;
					}
				}
				.btn{
					width: 180rpx;
					height: 66rpx;
					border-radius: 33rpx;
					color: #fff;
					font-size: 28rpx;
					background-color: $xzfx-theme;
					display: flex;
					justify-content: center;
					align-items: center;
				}
			}
		}
	}
	.action{
		position: fixed;
		left: 0;
		bottom: 0;
		z-index: 2;
		width: 100%;
		height: 120rpx;
		background-color: #fff;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding: 0 $xzfx-spacing;
		border-top: 1rpx solid #f1f1f1;
		.btn{
			width: calc(50% - 15rpx);
			height: 80rpx;
			border-radius: 40rpx;
			color: $xzfx-theme;
			display: flex;
			justify-content: center;
			align-items: center;
			border: 1rpx solid $xzfx-theme;
		}
		.btn:last-child{
			width: calc(50% - 15rpx);
			height: 80rpx;
			border-radius: 40rpx;
			color: #fff;
			background-color: $xzfx-theme;
			display: flex;
			justify-content: center;
			align-items: center;
		}
	}
</style>
